package fr.umlv.m2.jee.spij.service.unit;

import org.springframework.binding.message.MessageContext;

import javax.faces.model.SelectItem;
import java.util.List;

/**
 * Provides methods to retrieve units into databases from DAO.
 *
 * @author thomas magny
 * @author mathieu mazzolini
 */
public interface IDisplayUnitService {

    /**
     * Returns all the units which are inside the database.
     *
     * @param context the message context.
     *
     * @return a list of DTO Unit.
     */
    List<DisplayUnit> getAllDisplayUnit(MessageContext context);

    /**
     * Returns a unit from its id.
     *
     * @param id      the id which is the primary key of unit into the database.
     * @param context the message context.
     *
     * @return a DTO unit.
     */
    DisplayUnit getUnitById(long id, MessageContext context);

    /**
     * Persists into database as a unit the data provided.
     *
     * @param unit    the data to persist.
     * @param context the message context.
     *
     * @return true whether the unit has been persisted correctly,
     *         false otherwise.
     */
    boolean createUnit(DisplayUnit unit, MessageContext context);

    /**
     * Removes from database the unit given by its id provided in argument.
     *
     * @param id      the unit id to remove.
     * @param context the message context.
     *
     * @return true whether the unit has been removed correctly,
     *         false otherwise.
     */
    boolean deleteUnitById(long id, MessageContext context);

    /**
     * Merges a unit with the data provided into the DTO unit object.
     *
     * @param modifiedUnit the data to merge.
     * @param context      the message context.
     *
     * @return true whether the unit has been updated correctly,
     *         false otherwise.
     */
    boolean updateUnitById(DisplayUnit modifiedUnit, MessageContext context);

    /**
     * ...
     *
     * @param context the message context.
     *
     * @return a list of selected item.
     */
    List<SelectItem> getAllDisplayUnitSelectItem(MessageContext context);
}
